package com.survey.demo.ui.fragment;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.base.BaseDialog;
import com.survey.demo.R;
import com.survey.demo.app.TitleBarFragment;
import com.survey.demo.ui.activity.HomeActivity;
import com.survey.demo.ui.dialog.MenuDialog;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class SendFragment extends TitleBarFragment<HomeActivity> {
    private RecyclerView recycler;
    public static SendFragment newInstance() {
        return new SendFragment();
    }
    @Override
    protected int getLayoutId() {
        return R.layout.send_activity;
    }

    @Override
    protected void initView() {
        String[] kinds = getResources().getStringArray(R.array.send_kind);
        recycler= findViewById(R.id.rv_center);
        recycler.setLayoutManager(new GridLayoutManager(getActivity(),4));
        BaseQuickAdapter adapter =new BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_re_center_top, Arrays.asList(kinds)) {
            @Override
            protected void convert(@NotNull BaseViewHolder baseViewHolder, String bean) {
                baseViewHolder.setText(R.id.tv_menu_title_home,bean);
            }
        };
        recycler.setAdapter(adapter);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                   if(position==0){
                       String[] kinds = getResources().getStringArray(R.array.qyzp_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==1){
                       String[] kinds = getResources().getStringArray(R.array.zzdb_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==2){
                       String[] kinds = getResources().getStringArray(R.array.xqhz_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==3){
                       String[] kinds = getResources().getStringArray(R.array.znpx_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==4){
                       String[] kinds = getResources().getStringArray(R.array.qyzx_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==5){
                       String[] kinds = getResources().getStringArray(R.array.xmdj_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==6){
                       String[] kinds = getResources().getStringArray(R.array.rjxs_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }else if(position==7){
                       String[] kinds = getResources().getStringArray(R.array.yqpj_select);
                       // 底部选择框
                       new MenuDialog.Builder(getActivity())
                               .setList(kinds)
                               .setTitle("请选择发布类型")
                               .setListener(new MenuDialog.OnListener<String>() {
                                   @Override
                                   public void onSelected(BaseDialog dialog, int position, String string) {
                                       toast("位置：" + position + "，文本：" + string);
                                   }

                                   @Override
                                   public void onCancel(BaseDialog dialog) {
                                       toast("取消了");
                                   }
                               }).show();
                   }
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    public boolean isStatusBarEnabled() {
        // 使用沉浸式状态栏
        return !super.isStatusBarEnabled();
    }
}
